﻿using System;
using Domain.Engine.Commands;
using Service.Contract;
using SimpleCqrs.Commanding;

namespace Service
{
  public class HelloService : IHelloService
  {
    private readonly ICommandBus _commandBus;

    public HelloService(ICommandBus commandBus)
    {
      _commandBus = commandBus;
    }

    public string SayHello(string value)
    {
      var command = new SayHelloCommand
      {
        Name = value
      };
      if (_commandBus.Execute(command) > 0)
      {
        throw new InvalidOperationException("Command rejected");
      }

      return value + " echo";
    }
  }
}